//
//  BaseViewController.m
//  51-Tour
//
//  Created by xiang ying on 14-3-18.
//  Copyright (c) 2014年 xiang ying. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController
@synthesize contentView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
//        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    return self;
}


- (void)dealloc{
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)initNavigationItme:(NSString*)title
{
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, 320, 44)];
    titleView.backgroundColor = [UIColor clearColor];
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"topbar-bg_02"]];
    imageView.frame = CGRectMake(-8, 0, 320, 44);
    imageView.userInteractionEnabled = YES;
    [titleView addSubview:imageView];
    
    UIButton *leftbtn = [[UIButton alloc] initWithFrame: CGRectMake(0, 0, 44, 44)];
    [leftbtn setImage:[UIImage imageNamed:@"ic-back_02"] forState:UIControlStateNormal];
    [imageView addSubview:leftbtn];
    [leftbtn addTarget:self action:@selector(popself) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 7, 200, 35)];
    [titleLabel setText:title];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [titleLabel setTextColor:THEMECOLOR];
    titleLabel.backgroundColor = [UIColor clearColor];
    [imageView addSubview:titleLabel];
    
    [self.navigationItem setHidesBackButton:YES];
    self.navigationItem.titleView =  titleView;
}

- (void)popself{
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)loadView
{
    [super loadView];

    UIImageView *_bg = [[UIImageView alloc] initWithFrame:self.view.bounds];
    _bg.image = [UIImage imageNamed:@"bg"];
    [self.view addSubview:_bg];
    
    CGFloat height = [[UIScreen mainScreen] bounds].size.height;
    //(去除状态栏)
    CGFloat originY = 0;
    if (IOS7) {
        originY = 20+44;
    }
    CGRect rect = CGRectMake(0, originY, self.view.frame.size.width, height-64);
    contentView = [[UIScrollView alloc] initWithFrame:rect];
    [self.view addSubview:contentView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
